/**
 *
 */
package com.ssyt.examinationsystem.dao.impl;

import com.jdbc.util.JdbcUtils;
import com.ssyt.examinationsystem.dao.IArrangeInfoDAO;
import com.ssyt.examinationsystem.entity.ArrangeInfo;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class ArrangeInfoDAOImpl implements IArrangeInfoDAO {

    @Override
    public Map<String, Object> getArrangeInfoByClassId(String classId, String courseId) {
        String sql = "select * from arrangeInfo where classId = ? and courseId=?";
        List<Map<String, Object>> list = JdbcUtils.executeQuery(sql, classId, courseId);

        return list != null && list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public List<Map<String, Object>> getArranges() {
        return JdbcUtils.executeQuery("select * from arrangeInfo");
    }

    @Override
    public int updateArrange(ArrangeInfo arrnge) {
        String sql = "update arrangeInfo set paperId=?,classId=?,teaId=?,leader=?,startTime=?,endTime=?,address=?,courseId=? where arrangeId=? ";
        Object[] parameters = {arrnge.getPaper().getPaperId(), arrnge.getClassId(), arrnge.getTea().getTeaId(),
                arrnge.getLeader().getTeaId(), arrnge.getStartTime(), arrnge.getEndTime(), arrnge.getAddress(),
                arrnge.getCourse().getCourseId(), arrnge.getArrangeId()};

        return JdbcUtils.executeUpdate(sql, parameters);
    }

    @Override
    public int addArrange(ArrangeInfo arrnge) {
        String sql = "insert into arrangeInfo values(null,?,?,?,?,?,?,?,?)";
        Object[] parameters = {arrnge.getPaper().getPaperId(), arrnge.getClassId(), arrnge.getTea().getTeaId(),
                arrnge.getLeader().getTeaId(), arrnge.getStartTime(), arrnge.getEndTime(), arrnge.getAddress(),
                arrnge.getCourse().getCourseId()};
        return JdbcUtils.executeUpdate(sql, parameters);
    }

    @Override
    public int deleteArrange(String arrangeId) {
        return JdbcUtils.executeUpdate("delete from arrangeInfo where arrangeId=?", arrangeId);
    }
}
